package com.neusoft.demo9;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Map集合
 */
public class MapDemo {
    public static void main(String[] args) {
        //创建一个Map集合容器
        Map<String,String> maps = new HashMap<>();
        //向map集合中添加元素
        maps.put("1","fender");
        maps.put("2","gibson");
        maps.put("3","yamaha");
        //获取某个元素(根据key)
        String name =  maps.get("2");
        System.out.println(name);
        //如何遍历Map集合
        Set<Map.Entry<String,String>> set = maps.entrySet();
        Iterator<Map.Entry<String,String>> it = set.iterator();
        while (it.hasNext()) {
            Map.Entry<String,String> m = it.next();
            String k = m.getKey();
            String v = m.getValue();
            System.out.println(k+"---"+v);
        }
    }
}
